package com.huangd.platform.common.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class IOUtils {

	public static void close(AutoCloseable closeable) {

		if (closeable == null)
			return;

		try {
			closeable.close();
		} catch (Exception e) {
		}
	}

	public static String read(InputStream is) throws IOException {
		return read(is, "utf8");
	}

	public static String read(InputStream is, String encoding) throws IOException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();

		byte[] bytes = new byte[1024];

		int len = 0;
		while ((len = is.read(bytes)) != -1)
			baos.write(bytes, 0, len);

		String content = new String(baos.toByteArray(), encoding);
		return content;
	}
}
